/*
 * CAN_Module.c
 *
 *  Created on: Sep 2, 2021
 *      Author: ZhangJianCe
 */

#include "CAN_Module.h"

#ifdef CAN0_ON

	#ifdef CAN0_MB0_RX_ON
		#ifndef CAN0_MB0_Address
		CAN_RX_Frame CAN0_MB0_Buff;
		#endif
	#endif
	#ifdef CAN0_MB0_TX_ON
		#ifndef CAN0_MB0_Address
			CAN_TX_Frame CAN0_MB0_Buff;
		#endif
	#endif
#endif



void CAN_Transmit(CAN_HandleTypeDef *hcan,CAN_TX_Frame *Frame_Info)
{
	CAN_TxHeaderTypeDef pHeader;
	uint32_t SendMB;
	pHeader.IDE = Frame_Info->Extended==1?CAN_ID_EXT:CAN_ID_STD;
	if(pHeader.IDE == CAN_ID_STD)
	{
		pHeader.StdId = Frame_Info->ID;
	}
	else
	{
		pHeader.StdId = Frame_Info->ID>>18;
		pHeader.ExtId = Frame_Info->ID&0x3ffff;
	}
	pHeader.DLC = Frame_Info->Length;
	pHeader.RTR = Frame_Info->Remote==1?CAN_RTR_REMOTE:CAN_RTR_DATA;

	HAL_CAN_AddTxMessage(hcan, &pHeader, Frame_Info->Data, &SendMB);
}
